using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Microsoft.Practices.CompositeUI.SmartParts;
using LibrErian.Model;
using Microsoft.Practices.ObjectBuilder;
using System.Collections;

namespace LibrErian.Modules.BasicBook
{
    [SmartPart]
    public partial class SelectAuthorView : UserControl, ISelectAuthorView 
    {
        private SelectAuthorViewPresenter presenter;
        private Author selectedAuthor;

        [CreateNew]
        public SelectAuthorViewPresenter Presenter
        {
            set
            {
                presenter = value;
                presenter.View = this;
            }
        }

        public Author SelectedAuthor
        {
            get
            {
                return selectedAuthor;
            }
            set
            {
                selectedAuthor = value;
            }
        }

        public void SetData(IList authors)
        {
            dgvAuthors.DataSource = authors;
        }

        public SelectAuthorView()
        {
            InitializeComponent();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            if (dgvAuthors.SelectedRows.Count > 0)
            {
                selectedAuthor = dgvAuthors.SelectedRows[0].DataBoundItem as Author;
            }

            presenter.OnOk();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            presenter.OnCancel();
        }

        private void btnNew_Click(object sender, EventArgs e)
        {
            presenter.OnNew();
        }

        private void SelectAuthorView_Load(object sender, EventArgs e)
        {
            presenter.OnViewReady();
        }
    }
}
